package com.tyk.bookstore.back.comment.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.tyk.bookstore.back.comment.model.query.ReplyAddQuery;
import com.tyk.bookstore.back.comment.model.query.ReplyPageQuery;
import com.tyk.bookstore.back.comment.model.vo.ReplyPageVo;
import com.tyk.bookstore.back.comment.service.ReplyService;
import com.tyk.bookstore.back.common.core.model.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author tyk
 * @description 回复管理
 */
@Tag(name = "评论管理/回复管理", description = "回复管理")
@RequestMapping({"api/message/reply"})
@RestController
@RequiredArgsConstructor
public class ReplyController {

    private final ReplyService replyService;



    @Operation(summary = "分页查询回复", description = "分页查询回复")
    @SaCheckPermission("message:reply:page")
    @GetMapping("page")
    public R<ReplyPageVo> reply(
            @Validated @ParameterObject ReplyPageQuery query
    ) {
        return R.ok(replyService.getPage(query));
    }



    @Operation(summary = "回复评论/回复", description = "回复评论/回复")
    @SaCheckPermission("message:reply:add")
    @PostMapping
    public R<Object> reply(
            @Validated @RequestBody ReplyAddQuery query
    ) {
        replyService.reply(query);
        return R.ok();
    }


    @Operation(summary = "删除回复", description = "删除回复")
    @SaCheckPermission("message:reply:delete")
    @DeleteMapping({"{id}"})
    public R<Object> deleteById(
            @Schema(description = "回复ID") @NotNull @Min(1)
            @PathVariable Long id
    ) {
        replyService.deleteById(id);
        return R.ok();
    }
}
